<template>
  <div>
    <!--询价-->
    <el-dialog
      :title="inputInquiry"
      :visible.sync="dialogVisible10"
      :before-close="handleClose10"
      width="1100px"
    >
      <div>
        <el-form
          size="mini"
          :model="sendForm10"
          label-width="100px"
          ref="sendForm10"
          :rules="rules10"
        >
          <el-row>
            <el-col :span="24">
              <el-form-item label="客户名称:" prop="customerName">
                <el-select
                  clearable
                  v-model="sendForm10.customerName"
                  @change="handleCustomId"
                  filterable
                  remote
                  reserve-keyword
                  placeholder="请输入关键词"
                  :remote-method="companyQuerySearch"
                  style="width: 240px;"
                >
                  <el-option
                    v-for="item in companyQuerySearchList"
                    :key="item.customerId"
                    :label="item.customerName"
                    :value="item"
                  >
                  </el-option>
                </el-select>
                <div style="padding-left:15px;color:red;font-size: 12px" v-if="isEnableOrder === 0">注意:该客户最近1年存在降价违约{{ defaultNum }}次,超期未清款{{outTimeUnPaidAmount}}元，限制询盘和下单!</div>
                <!-- <el-button type="text" style="margin-left: 5px" @click="showPop8">新增客户</el-button> -->
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="客户标签:" v-if="customerTag">
            <crm-tag :item="item" v-for="item in customerTag" :key="item.tagName" style="margin-bottom:4px;margin-right:4px"></crm-tag>
          </el-form-item>
          <el-form-item label="负责人:">
            {{ chargeName }}
          </el-form-item>
          <el-form-item label="协助人:">
            {{ subChargeNames }}
          </el-form-item>
          <el-form-item label="业务员:" v-if="inquiryUserList.length==1">
            {{ inquiryUserList[0].userName }}
          </el-form-item>
          <el-form-item label="业务员:" prop="inquiryUserId" v-if="inquiryUserList.length>1">
            <el-select
              v-model="sendForm10.inquiryUserId"
              clearable
              filterable
            >
              <el-option
                v-for="item in inquiryUserList"
                :key="item.userId"
                :value="item.userId"
                :label="item.userName"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item  label="订单分类：" prop="saleCustomerType">
            <el-select v-model="sendForm10.saleCustomerType" filterable clearable>
              <el-option
                v-for="(item,index) in orderCustomerTypeList"
                :key="index"
                :label="item.cddValue"
                :value="item.cddValue">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-table
              :data="sendForm10.goodsList"
              border
              size="mini"
              :header-cell-style="{ background: '#f8f8f9', color: '#80878f' }"
              style="width: 100%; margin: 20px 0 0 -50px"
              ref="table"
            >
              <el-table-column align="center" label="品名牌号" width="280">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="`goodsList.${scope.$index}.goodsDetailId`"
                    :rules="rules10.goodsDetailId"
                    label-width="0px"
                  >
                  <el-select
                  v-model="scope.row.goodsDetailId"
                  placeholder="请选择/输入"
                  style="width: 90%"
                  filterable
                  remote
                  reserve-keyword
                  :remote-method="(query) => goodsQuerySearch(query, scope.row, scope.$index)"
                  @change="searchMember(scope.row.goodsDetailId, scope.$index,'changeGoods')"
                  >
                    <el-option-group
                      v-for="group in scope.row.goodsQuerySearchList"
                      :key="group.label"
                      :label="group.label">
                        <el-option
                          v-for="(item,index) in group.list"
                          :key="index"
                          :label="item.goodsName"
                          :value="item.goodsDetailId">
                        </el-option>
                      </el-option-group>
                    </el-select>
                    <div style="color:Red;text-align: left" v-if="scope.row.score  !=='' && scope.row.score < 80">询价商品竞争力小于80分！</div>
                  </el-form-item>
                  <el-form-item
                    v-if="scope.row.goodsDetailId && scope.row.isMallGoodsSn == 1"
                    :prop="`goodsList.${scope.$index}.isMallOrders`"
                    :rules="rules10.isMallOrders"
                    label="商城订单："
                  >
                    <el-radio-group v-model="scope.row.isMallOrders">
                      <el-radio :label="1">
                        <el-tooltip class="item" effect="light" placement="bottom-start">
                          <span><span style="vertical-align: middle">是</span><i class="el-icon-question" style="color:#606266;font-size: 16px;vertical-align: middle;padding-left:5px;"></i></span>
                          <div slot="content" style="width:400px;">采购需要通过供应商竞拍才能拿到的货，询盘后无法取消,确认客户需要拿货才能选择以该方式发起询盘</div>
                        </el-tooltip>
                      </el-radio>
                      <el-radio :label="0">否</el-radio>
                    </el-radio-group>

                  </el-form-item>

                </template>
              </el-table-column>
              <el-table-column label="数量（吨）" align="center" width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="`goodsList.${scope.$index}.goodsNum`"
                    :rules="rules10.goodsNum"
                    label-width="0px"
                  >
                    <el-input
                      style="width: 90%"
                      type="number"
                      clearable
                      v-model="scope.row.goodsNum"
                    ></el-input>
                    <div style="color:Red;line-height: 20px" v-if="scope.row.goodsNum > 30">
                      整车需要注意<br/>单车具体数量
                    </div>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="期望价格" align="center" width="120" >
                <template slot-scope="scope">
                  <el-form-item
                  label-width="0px"
                  :prop="`goodsList.${scope.$index}.expectGoodsPrice`"
                  >
                    <el-input
                      style="width: 90%"
                      clearable
                      type="number"
                      v-model="scope.row.expectGoodsPrice"
                    ></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="期望发货日期" align="center" width="180">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="`goodsList.${scope.$index}.receiveDate`"
                    :rules="rules10.receiveDate"
                    label-width="0px"
                  >
                    <el-date-picker
                      style="width: 90%"
                      value-format="yyyy-MM-dd"
                      :picker-options="pickerOptions1"
                      v-model="scope.row.receiveDate"
                      type="date"
                      @change="setIsPreorder"
                      placeholder="选择日期"
                    >
                    </el-date-picker>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column align="center" width="180" label="最晚发货日期">
                <template slot-scope="scope">
                  <el-form-item
                  label-width="0px"
                  :prop="`goodsList.${scope.$index}.latestReceiveDate`"
                  >
                    <el-date-picker
                      style="width: 90%"
                      v-model="scope.row.latestReceiveDate"
                      :picker-options="pickerOptions1"
                      value-format="yyyy-MM-dd"
                      type="date"
                      placeholder="选择日期"
                    >
                    </el-date-picker>
                  </el-form-item>
                </template>
              </el-table-column>
                <el-table-column align="center" width="180" label="发货紧急程度">
                  <template slot-scope="scope">
                    <el-form-item label-width="0px" :prop="`goodsList.${scope.$index}.inquiryUrgentType`">
                      <el-select
                        style="width: 90%"
                        v-model="scope.row.inquiryUrgentType"
                        clearable
                      >
                        <el-option
                        v-for="item in urgentTypeList"
                        :key="item.cddId"
                        :value="item.cddValue">
                          <div v-if="item.cddValue == '必须'">
                            <el-tooltip class="item" effect="light" placement="bottom-start">
                              <div><span style="vertical-align: middle">{{item.cddValue}}</span><i class="el-icon-question" style="color:#606266;font-size: 16px;vertical-align: middle;padding-left:5px;"></i></div>
                              <div slot="content" style="width:400px;">客户对及时发货要求非常严格，对延迟交货0容忍时选择此种紧急程度</div>
                            </el-tooltip>

                          </div>
                          <div v-else>{{item.cddValue}}</div>
                        </el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item
                    label-width="0px"
                    :prop="`goodsList.${scope.$index}.inquiryUrgentRemark`"
                    :rules="rules10.inquiryUrgentRemark"
                    v-if="scope.row.inquiryUrgentType == '必须'"
                    >
                    <el-input
                      v-model="scope.row.inquiryUrgentRemark"
                      placeholder="说明原因"
                      style="border: 1px solid #eee"
                    ></el-input>
                   </el-form-item>
                  </template>
                </el-table-column>
              <el-table-column align="center" width="120">
                <template slot="header" slot-scope="scope">
                  <el-tooltip class="item" effect="light" placement="bottom-start">
                    <div><span style="vertical-align: middle">收货方式</span><i class="el-icon-question" style="color:#606266;font-size: 16px;vertical-align: middle;padding-left:5px;"></i></div>
                    <div slot="content" style="width:400px;">部分仓库可能存在提货费，请及时联系物流或采购了解具体费用；发货前确保地址正确，发货后及时关注客户的收货情况，到货后及时联系客户将收货确认函盖章回传!</div>
                  </el-tooltip>
                </template>
                <template slot-scope="scope">
                  <el-form-item
                    :prop="`goodsList.${scope.$index}.sendTypes`"
                    :rules="rules10.sendTypes"
                    label-width="0px"
                  >
                    <el-select style="width: 90%" v-model="scope.row.sendTypes">
                      <el-option label="自提" value="自提"> </el-option>
                      <el-option label="送到" value="送到"> </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column align="center" width="220" label="收货地区">
                <template slot-scope="scope">
                    <!-- v-if="scope.row.sendTypes == '送到'" -->
                  <el-form-item
                    label-width="0px"
                    :prop="`goodsList.${scope.$index}.receiveAreaId`"
                    :rules="rules10.receiveAreaId"
                  >
                   <el-radio-group v-model="scope.row.radioFlag">
                    <el-radio :label="1">常用地址</el-radio>
                    <el-radio :label="2">自选地址</el-radio>
                  </el-radio-group>
                  <!-- :disabled="scope.row.sendTypes == '自提'" -->
                  <el-select v-model="scope.row.receiveAreaId" v-if="scope.row.radioFlag==1">
                    <el-option v-for="(item,index) in nearAreaList"
                    :key="index"
                    :label="item.receiveArea"
                    :value="item.receiveAreaId"></el-option>
                  </el-select>
                    <!-- :disabled="scope.row.sendTypes == '自提'" -->
                  <el-cascader
                    v-if="scope.row.radioFlag == 2"
                    style="width: 90%"
                    filterable
                    clearable
                    v-model="scope.row.receiveAreaId"
                    :props="{
                      value: 'areaId',
                      label: 'areaName',
                      children: 'children',
                    }"
                    :options="options"
                  ></el-cascader>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column align="center" width="120" label="结算方式">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="`goodsList.${scope.$index}.payTypes`"
                    :rules="rules10.payTypes"
                    label-width="0px"
                  >
                    <el-select style="width: 90%" v-model="scope.row.payTypes">
                      <el-option label="现汇" value="现汇"> </el-option>
                      <el-option label="承兑" value="承兑"> </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column align="center" width="100" label="备注">
                <template slot-scope="{ row }">
                  <el-form-item label-width="0px">
                    <el-input
                      style="width: 90%"
                      v-model="row.inquiryRemark"
                    ></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column
                label="向其他负责人询价"
                width="280"
                align="center"
                fixed="right"
              >
                <template slot-scope="scope">
                  <el-checkbox-group v-model="scope.row.assistUserIds">
                    <el-checkbox
                      v-for="item in scope.row.searchMemberList"
                      :key="item.userId"
                      :label="item.userId"
                    >
                      {{ item.userRealName }}
                    </el-checkbox>
                  </el-checkbox-group>
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                width="100"
                align="center"
                fixed="right"
              >
                <template slot-scope="scope">
                  <el-button
                    :disabled="sendForm10.goodsList.length<=1"
                    type="text"
                    size="mini"
                    @click="delInquiry(scope.$index)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
            <el-button
              v-if="type != 'copy'"
              type="text"
              size="small"
              @click="addInquiry()"
              style="margin-left: -50px"
              >增加询价</el-button
            >
          </el-form-item>

          <div style="display: flex;justify-content: flex-start;align-items: center">
            <el-form-item label="是否预售：" prop="isPreorder">
              <el-radio-group v-model="sendForm10.isPreorder">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否分批发货：" label-width="140px" v-if="goodsNumSum >= 35" style="margin-left: 100px" prop="isBatchPaid">
              <el-radio-group v-model="sendForm10.isBatchPaid">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
          <div style="font-size: 12px;color:red">预售订单定义：支付时未付全款且（下单到预计发货时间超过15天/分批发货）的订单</div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose10">取消</el-button>
        <el-button
          :disabled="isEnableOrder === 0"
          type="primary"
          @click="handleConfirm10"
          :loading="btnLoading10"
          >确认</el-button
        >
      </span>
    </el-dialog>

    <!-- <addCustomer ref="addCustomer"></addCustomer>

    <addGoodsSn ref="addGoodsSn"></addGoodsSn> -->
  </div>
</template>
<script>
import {
  getCustomerList,
  addInquiryPrice,
  getAreaList,
  getGoodsList,
  getInquiryDetail,
  getAssistUserListAPI,
  getLastInquiryAPI,
  getGoodsAreaAPI,
  getSaleUserListAPI
} from "@/api/allInLine/inquiry";
import { urgentTypeList } from "@/utils/constant";
import {getCustomerDefaultNum} from "@/api/order";
import {getGoodsScore} from "@/api/allInLine/goods";
import {getConfigList} from '@/api/partner';
// import addCustomer from "./addCustomer";
// import addGoodsSn from "./addGoodsSn";
import crmTag from "@/views/components/crmTag";
import { mapGetters } from "vuex";
import { Message } from "element-ui";
import {formatDate} from '@/utils/date';
const defaultSendForm10 = {
  companyId: "", //客户名称id
  customerName: "",
  inquiryUserId:"",
  saleCustomerType:'',
  goodsList: [],
  isBatchPaid:'',
  isPreorder:''
};
const defaultGoodsList = {
  receiveAreaId: "",
  goodsDetailId: "",
  goodsNum: "",
  expectGoodsPrice: "",
  sendTypes: "",
  receiveDate: "",
  latestReceiveDate: "",
  payTypes: "",
  inquiryRemark: "",
  searchMemberList: [],
  assistUserIds: [],
  inquiryUrgentType:"可延1-2天",//发货紧急程度
  inquiryUrgentRemark: "",//紧急程度备注
  radioFlag:2,
  score:'',
  isMallOrders:'' ,//是否是商城订单
  isMallGoodsSn:'',//是否是商城商品
  goodsQuerySearchList:[]
};
export default {
  name: "index",
  data() {
    const validateGoodsNum = (rule, value, callback) => {
      if (value < 0) {
        callback(new Error('数量不能小于0吨'))
      }
      callback()
    };
    return {
      // goodsAreaOptions:[],
      urgentTypeList: urgentTypeList,
      inquiryUserList:[],
      dialogVisible10: false,
      btnLoading10: false,
      inputInquiry: "",
      type: "",
      sendForm10: JSON.parse(JSON.stringify(defaultSendForm10)),
      rules10: {
        customerName: [
          { required: true, message: "请选择客户名称", trigger: "change" },
        ],
        inquiryUserId: [
          { required: true, message: "请选择业务员", trigger: "change" },
        ],
        goodsDetailId: [
          { required: true, message: "请选择牌号", trigger: "change" },
        ],
        isMallOrders:[
          { required: true, message: "请选择是否为商城订单", trigger: "change" },
        ],
        receiveDate: [
          { required: true, message: "请选择期望发货日期", trigger: "change" },
        ],
        goodsNum: [
          { required: true, message: "请输入数量", trigger: "blur" },
          {validator:validateGoodsNum,trigger: "blur"}
        ],
        sendTypes: [
          { required: true, message: "请选择收货方式", trigger: "change" },
        ],
        payTypes: [
          { required: true, message: "请选择结算方式", trigger: "change" },
        ],
        receiveAreaId: [
          { required: true, message: "请选择收货地区", trigger: "change" },
        ],
        inquiryUrgentRemark: [
          { required: true, message: "请输入紧急程度备注", trigger: "blur" },
        ],
        saleCustomerType: [
          { required: true, message: "请选择订单分类", trigger: "change" },
        ],
        isBatchPaid:[{ required: true, message: "此项必填", trigger: "change" },],
        isPreorder:[{ required: true, message: "此项必填", trigger: "change" },]
      },
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        },
      },
      pickerOptions2: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        },
      },
      companyQuerySearchList: [],
      goodsQuerySearchList: [],
      goodsList: [],
      diQuIds: [],
      data: [],
      options: [],
      data2: [],
      chargeName: "",
      subChargeNames:"",
      nearUseGoodsList: [],
      nearAreaList:[],
      defaultNum:0,
      orderCustomerTypeList:[],
      customerTag:'',
      isEnableOrder:'',
      outTimeUnPaidAmount:0
    };
  },
  computed: {
    ...mapGetters(["name", "mobile", "userId"]),
    goodsNumSum(){
      let sum = 0
      this.sendForm10.goodsList.forEach((el)=>{
        let goodsNum = el.goodsNum ? parseFloat(el.goodsNum): 0
        sum = sum + goodsNum
      })
      console.log("sum",sum)
      return sum
    },
  },
  components: {
    // addCustomer,
    // addGoodsSn,

    crmTag
  },
  created() {
  },
  filters: {},
  methods: {
    setIsPreorder(){
      let i =  this.sendForm10.goodsList.findIndex((el)=>{
        if(el.receiveDate){
          return this.getDaysDifference(new Date(),new Date(el.receiveDate)) >= 10
        }
      })
      if(i != -1){
        this.sendForm10.isPreorder = ''
      }else{
        this.sendForm10.isPreorder = 0
      }
    },
    //比较时间相关的天数
    getDaysDifference(date1, date2) {
      const diffTime = Math.abs(date2.getTime() - date1.getTime());
      const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
      return diffDays;
    },
    addDay(dayNumber, date) {
      date = date ? date : new Date();
      let ms = dayNumber * (1000 * 60 * 60 * 24)
      let newDate = new Date(date.getTime() + ms);
      return  formatDate(newDate, "yyyy-MM-dd");
    },

    //获取订单分类列表
    getOrderCustomerType(){
      getConfigList({status:1}).then((res)=>{
        let orderCustomerType = res.find((el)=>{
          return  el.cdtCode == 'order_customer_type'
        })
        this.orderCustomerTypeList = orderCustomerType ? orderCustomerType.data : []
      })
    },
    // 获取指定产品线协助人
    async searchMember(id, index,type) {
      if (id) {
        const res = await getAssistUserListAPI({ goodsDetailId: id });
        let c = JSON.parse(JSON.stringify(this.sendForm10.goodsList[index]))
        if(type == 'changeGoods'){
          c.isMallOrders = ''
          c.isMallGoodsSn = ''
        }
        c.searchMemberList=res
        // console.log("c1",c)
        this.sendForm10.goodsList.splice(index,1,c)
        //获取所选商品的竞争力
        let array = []
        c.goodsQuerySearchList.forEach((el)=>{
          array = array.concat(el.list);
        })
        let cutIndex = array.findIndex((el)=>{
          return el.goodsDetailId == id
        })

        if(cutIndex != -1){
          let sapGoodsId = array[cutIndex]['sapGoodsId']
          c.isMallGoodsSn = array[cutIndex]['isMallGoodsSn']
          getGoodsScore({sapGoodsId}).then((res)=>{
            c.score = res.score
            this.sendForm10.goodsList.splice(index,1,c)
          })
        }
      }
    },
    // 增加询价
    addInquiry() {
      const data = JSON.parse(JSON.stringify(defaultGoodsList));
      data.goodsQuerySearchList = [];
      data.goodsQuerySearchList.push(
        {
        label: '常用商品',
        list: this.nearUseGoodsList.length > 0 ? this.nearUseGoodsList :[]
        },
        {
        label: '商品',
        list: []
        })
      this.sendForm10.goodsList.push(data);
      this.setIsPreorder()
    },
    delInquiry(index) {
      this.sendForm10.goodsList.splice(index, 1);
      this.setIsPreorder()
      // this.searchMemberList.splice(index, 1);
    },
    //客户名称输入匹配
    companyQuerySearch(queryString) {
      if (queryString && queryString != "") {
        getCustomerList({ keywords: queryString, key: "my" }).then((res) => {
          this.companyQuerySearchList = res;
        });
      }
    },
    getCustomerWy(){
      this.defaultNum = 0
      this.customerTag = ''
      if(this.sendForm10.companyId){
        getCustomerDefaultNum({customerId:this.sendForm10.companyId}).then((res)=>{
          this.defaultNum = res.defaultNum
          this.isEnableOrder = res.isEnableOrder
          this.outTimeUnPaidAmount = res.outTimeUnPaidAmount
          this.customerTag = res.customerTag
        })
      }
    },
    // 更换客户名称
    handleCustomId(val) {
      this.sendForm10.customerName = val.customerName;
      this.sendForm10.companyId = val.customerId;
      this.sendForm10.goodsList = []
      this.chargeName = val.chargeName;
      this.subChargeNames = val.subChargeNames;
      if(this.sendForm10.companyId){
        this.getLastInquiry(val.customerId)
        this.getCustomerWy()
      }

      // let text = [];
      // if (val.customerId) {
      //    val.goodsLineCharge.forEach((el) => {
      //     text.push(el.lineName + "-" + el.userRealName);
      //   });
      //   this.goodsName = text.join(",");
      // }
    },
    // 根据客户名称获取业务员列表
    getSaleUserList() {
      getSaleUserListAPI({
        type:"inquiry"
      }).then((res) => {
        this.inquiryUserList = res;
        if (this.inquiryUserList.length == 1) {
          this.sendForm10.inquiryUserId=this.inquiryUserList[0].userId
        }
      }).catch((error) => {
        console.log(error);
      })
    },
    // 根据客户名称获取上次询价内容
    getLastInquiry(customerId) {
      getLastInquiryAPI({
        customerId: customerId
      }).then((res) => {
        if (res.companyId) {//有值
          let c = {}
          for (let key in defaultGoodsList) {
            c[key] =res[key] ? res[key]: defaultGoodsList[key]
          }
          c.goodsNum = ""
          c.receiveDate= this.addDay(2)
          c.latestReceiveDate = ""
          c.expectGoodsPrice=""
          // console.log("c",c)
          this.sendForm10.goodsList.splice(0, 1, c)
          // console.log(this.sendForm10.goodsList)
          this.setIsPreorder()
          // 获取产品线协助人
          this.searchMember(res.goodsDetailId,0)
          let lastGoodsDetail = res.goodsName + ' ' + res.brandName + ' ' + res.goods_sn
          this.getNearUse().then((res) => {
            this.goodsQuerySearch(lastGoodsDetail, this.sendForm10.goodsList[0], 0,'changeCustomId')
          })
        } else {//返回值为空数组
          this.addInquiry()
        }
      }).catch(() => { })
    },
    // 获取常用信息
    getNearUse() {
     return getGoodsAreaAPI({
        customerId: this.sendForm10.companyId
     }).then((res) => {
       this.nearUseGoodsList = res.goodsArr  //常用商品
       this.nearAreaList=res.areaArr         //常用地址
      }).catch((error) => {
        console.log(error);
      })
    },

    //牌名输入匹配
    goodsQuerySearch(queryString, scope, index, type) {
      if (type == 'changeCustomId') {
        const data1 = JSON.parse(JSON.stringify(scope));
        data1.goodsQuerySearchList = []
        data1.goodsQuerySearchList.push({
          label: '常用商品',
          list: this.nearUseGoodsList
        }, {
          label: '商品',
          list: []
        })
        this.sendForm10.goodsList.splice(index, 1, data1);
      } else if (queryString && queryString != "") {
        getGoodsList({
          goodsName: queryString,
          goodsSn: "",
          goodsType: "",
          pageNum: 1,
          pageSize: 1000,
        }).then((res) => {
          const data1 = JSON.parse(JSON.stringify(scope));
          data1.goodsQuerySearchList = []
          data1.goodsQuerySearchList.push({
            label: '常用商品',
            list: this.nearUseGoodsList
          },{
            label: '商品',
            list: res.list
          })
          this.sendForm10.goodsList.splice(index, 1, data1);
        });
      }
    },

    //显示询价
     async showPop10(type,item) {
       this.defaultNum = 0
       this.dialogVisible10 = true;
       this.getAddressListData();
       this.getOrderCustomerType();
       defaultGoodsList.receiveDate = this.addDay(2)
       if (type == 'add') {
        this.inputInquiry = "发布询价";
        this.getSaleUserList();
        setTimeout(() => {
          this.$refs.table.doLayout();
          this.addInquiry();
        }, 500);
       }
       if (type == 'edit') {
         this.inputInquiry = "复制询价";
         getInquiryDetail({
           inquiryId: item.inquiryId
         }).then(async (res) => {
           this.sendForm10 = JSON.parse(JSON.stringify(defaultSendForm10));
           const data = JSON.parse(JSON.stringify(defaultGoodsList));
           this.sendForm10.customerName = res.customerName;
           this.sendForm10.companyId = res.companyId;
           this.getSaleUserList();
           this.goodsName = "";
           let text = [];
           res.goodsLineCharge.forEach((el) => {
             text.push(el.lineName + "-" + el.userRealName);
           });
           this.goodsName = text.join(",");
           for (let key in defaultGoodsList) {
            data[key] = (res[key] || res[key] === 0) ? res[key]: defaultGoodsList[key]
           }
           const res2 = await getGoodsList({
              goodsName: res.categoryName,
              goodsSn: res.goodsSn,
              goodsType: "",
              pageNum: 1,
              pageSize: 1000,
           });
            data.receiveDate =  ""
            data.latestReceiveDate = ""
            data.goodsQuerySearchList = []
            data.goodsQuerySearchList.push({
              label: '常用商品',
              list:res2.list
            })
            this.sendForm10.goodsList.push(data);
            this.setIsPreorder()
            this.searchMember(res.goodsDetailId, 0);//获取产品线协助人
           this.getCustomerWy()
           }).catch((error) => {
          console.log(error);
         })
       }
    },
    //关闭询价
    handleClose10() {
      this.sendForm10 = JSON.parse(JSON.stringify(defaultSendForm10));
      this.$refs.sendForm10.resetFields();
      this.dialogVisible10 = false;
    },

    //确认提交询价
    handleConfirm10() {
      this.$refs.sendForm10.validate((valid) => {
        if (valid) {
          this.btnLoading10 = true;
          const data = JSON.parse(JSON.stringify(this.sendForm10));
          delete data.customerName;
          data.goodsList.forEach((item) => {

            delete item.goodsQuerySearchList;
            if (item.receiveAreaId.length > 0) {
              item.receiveAreaId = item.receiveAreaId ? item.receiveAreaId[item.receiveAreaId.length - 1]: "";
              } else {
                item.receiveAreaId = item.receiveAreaId;
              }
            // if (item.sendTypes == "自提") {
            //   item.receiveAreaId = 0;
            // } else {
            // }
          });
          if(this.goodsNumSum < 35){
            data.isBatchPaid = ''
          }
          addInquiryPrice(data).then((res) => {
            this.sendForm10 = JSON.parse(JSON.stringify(defaultSendForm10));
            this.$refs.sendForm10.resetFields();
            Message.success("提交成功");
            this.$emit("update");
            this.dialogVisible10 = false;
            this.btnLoading10 = false;
          }).catch((error) => {
            console.log(error);
            this.btnLoading10 = false;
          });
        }
      });
    },
    //获取省市区列表
    getAddressListData() {
      getAreaList().then((res) => {
        this.options = res;
      });
    },
  },
};
</script>

<style  lang="scss">
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  width: 8px !important;
  height: 8px !important;
  background: #eeeeee !important;
}

::v-deep .el-table__body-wrapper::-webkit-scrollbar-track {
  border-radius: 10px !important;
  background: #eeeeee !important;
}

::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  border-radius: 10px !important;
  background: #eeeeee !important;
}
</style>
